//
//  CZUserAccountModel.swift
//  CZVVeiBo
//
//  Created by smile on 2017/7/31.
//  Copyright © 2017年 itcast. All rights reserved.
//

import UIKit
// 如果归档的话 需要继承NSCoding协议
class CZUserAccountModel: NSObject, NSCoding {

    /// 用户授权的唯一票据
    var access_token: String?
    /// access_token的生命周期，单位是秒数
    var expires_in: Double = 0 {
        didSet{
            expires_Date = Date().addingTimeInterval(expires_in)
        }
    }
    /// 授权用户的UID，本字段只是为了方便开发者，减少一次user/show接口调用而返回的
    var uid: String?
    /// 用户的昵称
    var screen_name: String?
    /// 用户头像
    var avatar_large: String?
    /// 判断用户过期时间 （当前日期+新浪微博返回的过期的秒数）
    var expires_Date: Date?
    
    override var description: String{
        let keys = ["access_token", "expires_in", "uid", "screen_name", "avatar_large"]
        return dictionaryWithValues(forKeys: keys).description
    }
    
    override init() {
        super.init()
    }
    
    // 归档(对象转二进制保存到磁盘)
    func encode(with aCoder: NSCoder) {
        self.yy_modelEncode(with: aCoder)
    }
    // 解档 (从磁盘中获取二进制转对象)
    required init?(coder aDecoder: NSCoder) {
        super.init()
        self.yy_modelInit(with: aDecoder)
    }
    
//    - (void)encodeWithCoder:(NSCoder *)aCoder { [self yy_modelEncodeWithCoder:aCoder]; }
    
//    - (id)initWithCoder:(NSCoder *)aDecoder { self = [super init]; return [self yy_modelInitWithCoder:aDecoder]; }
}
